package Rooms;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import Beans.EJB_Filters.*;
import Entities.RoomSearchEntity;

/**
 * Created by IntelliJ IDEA.
 * User: mchebanenko
 * Date: 4-Jan-2011
 * Time: 1:17:31 PM
 * To change this template use File | Settings | File Templates.
 */
public class RoomListFilter {

    private RoomListFltEntity flt = new RoomListFltEntity();
    private DataModel fltResult;
 //   private RoomDetails selectedRoomDetails;


    public DataModel getFltResult() {
        if (fltResult == null) {
                    fltResult = new ListDataModel();
       }
       fltResult.setWrappedData(getRoomList());
       return fltResult;
    }

    public RoomListFltEntity getFlt() {
        if (flt==null){
            flt = new RoomListFltEntity();
        }
        return flt;
    }

    public void setFlt(RoomListFltEntity flt) {
        this.flt = flt;
    }


    public List getRoomList (){
        List retVal;
         try{
                Context cont = new InitialContext();
                retVal = ((IRoomListFlt) cont.lookup("HotelManager/RoomListFltBean/local")).getRoomList(flt);
                //FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("RoomListFilter",this);
            } catch (Exception e) {
                e.printStackTrace();
                return  null;
            }

        return  retVal;
    }


/*    public RoomDetails getSelectedRoomDetails() {

         if (fltResult != null) {
               RoomDetails room = new RoomDetails();
               String room_id = room.getRoom_id();
               RoomSearchEntity[] lst = (RoomSearchEntity[]) fltResult.getWrappedData();
               for(int i =0 ; i< lst.length ; i++){
                   RoomSearchEntity rse = (RoomSearchEntity) lst[i];
                   if (rse.getRoom_id().toString().equals(room_id)) {
                       room.setFlt(flt);
                       room.setRoom(rse);
                       selectedRoomDetails= room;
                       return selectedRoomDetails;
                   }
               }
         }
        return selectedRoomDetails;
    }*/
}
